{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-10T07:21:15.052627Z",
     "start_time": "2018-09-10T07:21:14.673476Z"
    }
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import cv2\n",
    "from pathlib import Path\n",
    "from skimage import io\n",
    "\n",
    "import matplotlib.animation as ani\n",
    "from IPython.display import HTML\n",
    "import matplotlib\n",
    "matplotlib.rcParams['animation.embed_limit'] = 1000\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-10T07:21:15.445801Z",
     "start_time": "2018-09-10T07:21:15.440585Z"
    }
   },
   "outputs": [],
   "source": [
    "source_dir = Path('../data/source/test_img')\n",
    "target_dir = Path('../results/target/test_latest/images')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-10T07:21:16.041668Z",
     "start_time": "2018-09-10T07:21:16.015950Z"
    }
   },
   "outputs": [],
   "source": [
    "source_img_paths = sorted(source_dir.iterdir())\n",
    "target_synth_paths = sorted(target_dir.glob('*synthesized*'))\n",
    "target_label_paths = sorted(target_dir.glob('*input*'))\n",
    "\n",
    "len(source_img_paths) == len(target_synth_paths) == len(target_label_paths)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-10T07:21:16.768047Z",
     "start_time": "2018-09-10T07:21:16.731298Z"
    }
   },
   "outputs": [],
   "source": [
    "def animate(nframe):\n",
    "    ax1.clear()\n",
    "    ax2.clear()\n",
    "    ax3.clear()\n",
    "\n",
    "    source_img = io.imread(source_img_paths[nframe])\n",
    "    ax1.imshow(source_img)\n",
    "    ax1.set_xticks([])\n",
    "    ax1.set_yticks([])\n",
    "    \n",
    "    target_label = io.imread(target_label_paths[nframe])\n",
    "    ax2.imshow(target_label)\n",
    "    ax2.set_xticks([])\n",
    "    ax2.set_yticks([])\n",
    "    \n",
    "    target_synth = io.imread(target_synth_paths[nframe])\n",
    "    ax3.imshow(target_synth)\n",
    "    ax3.set_xticks([])\n",
    "    ax3.set_yticks([])    \n",
    "\n",
    "fig = plt.figure(figsize=(12, 6))\n",
    "ax1 = fig.add_subplot(131)\n",
    "ax2 = fig.add_subplot(132)\n",
    "ax3 = fig.add_subplot(133)\n",
    "\n",
    "anim = ani.FuncAnimation(fig, animate, frames=len(target_label_paths), interval=1000/24)\n",
    "plt.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-10T07:21:18.940190Z",
     "start_time": "2018-09-10T07:21:18.411259Z"
    }
   },
   "outputs": [],
   "source": [
    "js_anim = HTML(anim.to_jshtml())\n",
    "js_anim"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-10T00:36:11.422992Z",
     "start_time": "2018-09-10T00:35:23.687897Z"
    }
   },
   "outputs": [],
   "source": [
    "anim.save(\"output.gif\", writer=\"imagemagick\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "python3.6",
   "language": "python",
   "name": "python3.6"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  },
  "toc": {
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": "block",
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
